Accusoft.BarcodeXpress12.Net - Updated
Tutorial: Create Your First Project
User Guide > Getting Started > Tutorial: Create Your First Project

This step-by-step tutorial will guide you to build a complete C# application that analyzes 1D barcodes from an example image and outputs the value and type to a message box. This tutorial uses ImagXpress to handle any preprocessing before passing the image to the Barcode Xpress engine to be analyzed.

Prerequisites:

For this tutorial, we would recommend using Visual Studios 12 or higher.

Steps:

  1. Create a new C# Windows Form Application; we will use the default name (Form1).
  2. To the References add ImagXpress13.Net and BarcodeXpress12.Net which are typically located at "C:\Users\Public\Documents\Accusoft".       
  3. In the Form1.cs file, go to ToolBox >Accusoft, add an ImageXView. Also add two buttons.
  4. In your Solution Explorer, navigate to Form1.cs >Form1.Designer.cs and double-click to open it.
  5. The following should be there:
    Copy Code
    private Accusoft.ImagXpressSdk.ImageXView imageXView1;
    private Accusoft.ImagXpressSdk.ImagXpress imagXpress1;
    private System.Windows.Forms.Button button1;
    private System.Windows.Forms.Button button2;
  6. To that add:
    Copy Code
    private Accusoft.BarcodeXpressSdk.BarcodeXpress bx;
  7. In the Solution Explorer, select Form1.cs and press F7 on the keyboard to open in code view.
  8. Include the namespace in the project. At the top of the project add the following to Form1.cs:
    Copy Code
    using Accusoft.BarcodeXpressSdk;
  9. In public Form1(), after your InitializeComponent() call, create an instance of Barcode Xpress and set your license information:
    Copy Code
    bx = new BarcodeXpress();
    //bx.Licensing.SetSolutionName("SolutionNameGoesHere");
    //bx.Licensing.SetSolutionKey(keynumber, keynumber, keynumber, keynumber);
  10. In the Solution Explorer, double-click Form1.cs to open it in design view, Form1.cs[Design]).
  11. Within Form1.cs[Design], double-click button1 to create the click event handler in the code view.
  12. Within the “button1_Click” function you will load the image using ImagXpress:
    Copy Code
    try
    {
         if (imageXView1.Image != null)
              imageXView1.Image.Dispose();
         imageXView1.Image = Accusoft.ImagXpressSdk.ImageX.FromFile(imagXpress1, @"YourPathToYourBarcodeImage\BarcodeImage.bmp");
    }
    catch (Accusoft.ImagXpressSdk.ImagXpressException ex)
    {
         MessageBox.Show("Error Opening File. ImagXpress Error: " + ex.Message);
    }
  13. Go back to the Form1.cs[Design] file and double click button2 to create another click event handler in the code view.
  14. Within the “button2_Click” function you will analyze (read) the barcode and output the results in a Result array:
    Copy Code
    try
    {
         Accusoft.BarcodeXpressSdk.Result[] results = bx.reader.Analyze(imageXView1.Image);
         for (int i = 0; i < results.Length; i++)
         {
              string strResult = "";
    
              Accusoft.BarcodeXpressSdk.Result curResult = (Accusoft.BarcodeXpressSdk.Result)results.GetValue(i);
              strResult += "Symbol #" + i + "\r" + "Type = " + curResult.BarcodeName + "\r";
              strResult += "Value: = " + i + curResult.BarcodeValue + "\r";
    
              strResult += "\n";
              MessageBox.Show(strResult, "Barcode Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
          }
    }
    catch (Accusoft.ImagXpressSdk.ImagXpressException ex)
    {
         MessageBox.Show("Error Opening File. ImagXpress Error: " + ex.Message);
    }
  15. Finally, clean up the Barcode Xpress object by releasing unmanaged resources. Within the function “button2_Click”, but outside of the catch statement, place the following code.
    Copy Code
    bx.Dispose();